home *** CD-ROM | disk | FTP | other *** search
/ Software of the Month Club 2000 October / Software of the Month - Ultimate Collection Shareware 277.iso / pc / PROGRAMS / UTILITY / WINLINUX / DATA1.CAB / programs_-_include / ASM-I386 / IO.H < prev    next >
C/C++ Source or Header  |  1999-09-17  |  5KB  |  189 lines

  1. #ifndef _ASM_IO_H
  2. #define _ASM_IO_H
  3.  
  4. /*
  5.  * This file contains the definitions for the x86 IO instructions
  6.  * inb/inw/inl/outb/outw/outl and the "string versions" of the same
  7.  * (insb/insw/insl/outsb/outsw/outsl). You can also use "pausing"
  8.  * versions of the single-IO instructions (inb_p/inw_p/..).
  9.  *
  10.  * This file is not meant to be obfuscating: it's just complicated
  11.  * to (a) handle it all in a way that makes gcc able to optimize it
  12.  * as well as possible and (b) trying to avoid writing the same thing
  13.  * over and over again with slight variations and possibly making a
  14.  * mistake somewhere.
  15.  */
  16.  
  17. /*
  18.  * Thanks to James van Artsdalen for a better timing-fix than
  19.  * the two short jumps: using outb's to a nonexistent port seems
  20.  * to guarantee better timings even on fast machines.
  21.  *
  22.  * On the other hand, I'd like to be sure of a non-existent port:
  23.  * I feel a bit unsafe about using 0x80 (should be safe, though)
  24.  *
  25.  *        Linus
  26.  */
  27.  
  28.  /*
  29.   *  Bit simplified and optimized by Jan Hubicka
  30.   */
  31.  
  32. #ifdef SLOW_IO_BY_JUMPING
  33. #define __SLOW_DOWN_IO "\njmp 1f\n1:\tjmp 1f\n1:"
  34. #else
  35. #define __SLOW_DOWN_IO "\noutb %%al,$0x80"
  36. #endif
  37.  
  38. #ifdef REALLY_SLOW_IO
  39. #define __FULL_SLOW_DOWN_IO __SLOW_DOWN_IO __SLOW_DOWN_IO __SLOW_DOWN_IO __SLOW_DOWN_IO
  40. #else
  41. #define __FULL_SLOW_DOWN_IO __SLOW_DOWN_IO
  42. #endif
  43.  
  44. /*
  45.  * Talk about misusing macros..
  46.  */
  47. #define __OUT1(s,x) \
  48. extern inline void out##s(unsigned x value, unsigned short port) {
  49.  
  50. #define __OUT2(s,s1,s2) \
  51. __asm__ __volatile__ ("out" #s " %" s1 "0,%" s2 "1"
  52.  
  53. #define __OUT(s,s1,x) \
  54. __OUT1(s,x) __OUT2(s,s1,"w") : : "a" (value), "Nd" (port)); } \
  55. __OUT1(s##_p,x) __OUT2(s,s1,"w") __FULL_SLOW_DOWN_IO : : "a" (value), "Nd" (port));} \
  56.  
  57. #define __IN1(s) \
  58. extern inline RETURN_TYPE in##s(unsigned short port) { RETURN_TYPE _v;
  59.  
  60. #define __IN2(s,s1,s2) \
  61. __asm__ __volatile__ ("in" #s " %" s2 "1,%" s1 "0"
  62.  
  63. #define __IN(s,s1,i...) \
  64. __IN1(s) __IN2(s,s1,"w") : "=a" (_v) : "Nd" (port) ,##i ); return _v; } \
  65. __IN1(s##_p) __IN2(s,s1,"w") __FULL_SLOW_DOWN_IO : "=a" (_v) : "Nd" (port) ,##i ); return _v; } \
  66.  
  67. #define __INS(s) \
  68. extern inline void ins##s(unsigned short port, void * addr, unsigned long count) \
  69. { __asm__ __volatile__ ("cld ; rep ; ins" #s \
  70. : "=D" (addr), "=c" (count) : "d" (port),"0" (addr),"1" (count)); }
  71.  
  72. #define __OUTS(s) \
  73. extern inline void outs##s(unsigned short port, const void * addr, unsigned long count) \
  74. { __asm__ __volatile__ ("cld ; rep ; outs" #s \
  75. : "=S" (addr), "=c" (count) : "d" (port),"0" (addr),"1" (count)); }
  76.  
  77. #define RETURN_TYPE unsigned char
  78. __IN(b,"")
  79. #undef RETURN_TYPE
  80. #define RETURN_TYPE unsigned short
  81. __IN(w,"")
  82. #undef RETURN_TYPE
  83. #define RETURN_TYPE unsigned int
  84. __IN(l,"")
  85. #undef RETURN_TYPE
  86.  
  87. __OUT(b,"b",char)
  88. __OUT(w,"w",short)
  89. __OUT(l,,int)
  90.  
  91. __INS(b)
  92. __INS(w)
  93. __INS(l)
  94.  
  95. __OUTS(b)
  96. __OUTS(w)
  97. __OUTS(l)
  98.  
  99. #ifdef __KERNEL__
  100.  
  101. #include <linux/vmalloc.h>
  102. #include <asm/page.h>
  103.  
  104. #define __io_virt(x)        ((void *)(PAGE_OFFSET | (unsigned long)(x)))
  105. #define __io_phys(x)        ((unsigned long)(x) & ~PAGE_OFFSET)
  106. /*
  107.  * Change virtual addresses to physical addresses and vv.
  108.  * These are pretty trivial
  109.  */
  110. extern inline unsigned long virt_to_phys(volatile void * address)
  111. {
  112.     return __io_phys(address);
  113. }
  114.  
  115. extern inline void * phys_to_virt(unsigned long address)
  116. {
  117.     return __io_virt(address);
  118. }
  119.  
  120. extern void * __ioremap(unsigned long offset, unsigned long size, unsigned long flags);
  121.  
  122. extern inline void * ioremap (unsigned long offset, unsigned long size)
  123. {
  124.     return __ioremap(offset, size, 0);
  125. }
  126.  
  127. /*
  128.  * This one maps high address device memory and turns off caching for that area.
  129.  * it's useful if some control registers are in such an area and write combining
  130.  * or read caching is not desirable:
  131.  */
  132. extern inline void * ioremap_nocache (unsigned long offset, unsigned long size)
  133. {
  134.         return __ioremap(offset, size, _PAGE_PCD);
  135. }
  136.  
  137. extern void iounmap(void *addr);
  138.  
  139. /*
  140.  * IO bus memory addresses are also 1:1 with the physical address
  141.  */
  142. #define virt_to_bus virt_to_phys
  143. #define bus_to_virt phys_to_virt
  144.  
  145. /*
  146.  * readX/writeX() are used to access memory mapped devices. On some
  147.  * architectures the memory mapped IO stuff needs to be accessed
  148.  * differently. On the x86 architecture, we just read/write the
  149.  * memory location directly.
  150.  */
  151.  
  152. #define readb(addr) (*(volatile unsigned char *) __io_virt(addr))
  153. #define readw(addr) (*(volatile unsigned short *) __io_virt(addr))
  154. #define readl(addr) (*(volatile unsigned int *) __io_virt(addr))
  155.  
  156. #define writeb(b,addr) (*(volatile unsigned char *) __io_virt(addr) = (b))
  157. #define writew(b,addr) (*(volatile unsigned short *) __io_virt(addr) = (b))
  158. #define writel(b,addr) (*(volatile unsigned int *) __io_virt(addr) = (b))
  159.  
  160. #define memset_io(a,b,c)    memset(__io_virt(a),(b),(c))
  161. #define memcpy_fromio(a,b,c)    memcpy((a),__io_virt(b),(c))
  162. #define memcpy_toio(a,b,c)    memcpy(__io_virt(a),(b),(c))
  163.  
  164. /*
  165.  * Again, i386 does not require mem IO specific function.
  166.  */
  167.  
  168. #define eth_io_copy_and_sum(a,b,c,d)    eth_copy_and_sum((a),__io_virt(b),(c),(d))
  169.  
  170. static inline int check_signature(unsigned long io_addr,
  171.     const unsigned char *signature, int length)
  172. {
  173.     int retval = 0;
  174.     do {
  175.         if (readb(io_addr) != *signature)
  176.             goto out;
  177.         io_addr++;
  178.         signature++;
  179.         length--;
  180.     } while (length);
  181.     retval = 1;
  182. out:
  183.     return retval;
  184. }
  185.  
  186. #endif /* __KERNEL__ */
  187.  
  188. #endif
  189.